package com.lzh.gulimall.product.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.serializer.GenericJackson2JsonRedisSerializer;
import org.springframework.data.redis.serializer.RedisSerializer;
import org.springframework.session.web.http.CookieSerializer;
import org.springframework.session.web.http.DefaultCookieSerializer;

/**
 * @ClassName SessionConfig
 * @Description TODO
 * @Author liuzhihui
 * @Date 2020/9/1 13:32
 * @Version 1.0
 **/
@Configuration
public class SessionConfig {
    /**
     * 配置cookie
     * 修改cookie序列化方式
     * 解决：服务器与浏览器的sessionId不一样扥问题
     * https://blog.csdn.net/wzygis/article/details/103509840
     * @return
     */
    @Bean
    public CookieSerializer cookieSerializer(){
        DefaultCookieSerializer defaultCookieSerializer = new DefaultCookieSerializer();
        //放大子域
        defaultCookieSerializer.setDomainName("gulimall.com");
        defaultCookieSerializer.setCookieName("GULISESSION");
        defaultCookieSerializer.setUseBase64Encoding(false);

        return defaultCookieSerializer;
    }
    /**
     * 修改SpringSession序列化化机制
     */
    @Bean
    public RedisSerializer<Object> springSessionDefaultRedisSerializer () {
        return new GenericJackson2JsonRedisSerializer();
    }

}
